<template>
  <div>
    <keep-alive>
      <router-view></router-view>
    </keep-alive>
    <tabBar :isLink="true" @change="handleChange"></tabBar>
  </div>
</template>

<script>
  import TabBar from '@/components/TabBar'

  export default {
    name: "MainView",
    components:{
      TabBar
    },
    beforeRouteUpdate (to, from, next) {
      const path = to.path
      const tab = path.replace('/reader/','')
      this.$store.dispatch('switchTab',tab)
      next()
    },
    methods:{
      handleChange(val){
        this.$store.dispatch('switchTab',val)
        this.$router.push(`/reader/${val}`)
      }
    }
  }
</script>

<style >
  .none{
    text-align: center;
    font-size: 1.2em;
    margin-top: 20vh;
  }
</style>
